﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8">
<title>股票:三连涨前9</title>
<style>
	.divCenter{
		margin: auto;  
		position: absolute;  
        top: 0; left: 0; bottom: 0; right: 0;
	}
	.elementCenter{
		margin:auto;
		width:50%;
	}
</style>
</head>

<body style="background-color:black;">
	<div id="container" style="width:100%; height:auto; border:100px;">
		<div id="header" style="background-color:red;">
			<h1 style="text-align:center;">ChrismasIn2015</h1>
		</div>
		<!-- 头部 -->
		<div id="stock" style="background-color:yellow;height:200px;width:100%;
		position:relative;">
			<div id="function" class="divCenter" style="background-color:#02C874;height:160px;width:86%;">
				<div id="message1" class="elementCenter" style="weight:50%;height:100%;float:left;">
				
				<%@page import="java.io.File"%>
				<%@page import="java.sql.Connection"%>
				<%@page import="java.sql.DriverManager"%>
				<%@page import="java.sql.ResultSet"%>
				<%@page import="java.sql.SQLException"%>
				<%@page import="java.sql.Statement"%>
				<%@page import="java.lang.*"%>
				<%@page import="com.mysql.jdbc.Driver"%>
				
				<%
					String s1;
					String s2;
					String s3;
					String s4;
					String s5;
					String s6;
					String s7;
					String s8;
					String s9;
					String s10;
		
					String[][] s = null;
					
					Class.forName("com.mysql.jdbc.Driver");
					//加载驱动
						
					Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/stocks?useSSL=false","wqao","123456");
					//连接到一个数据库
						
					Statement statement0 = connection.createStatement();
					//创建传输器
						
					//statement0.executeUpdate("create table mytext (id int)");
					//传输器在数据库text中新建表mytext
					
					String order = "select max(count),code from mystocks group by code";
					ResultSet forCount = statement0.executeQuery(order);
					//把查询结果保存到set里
					int count = 0;
					while(forCount.next()) {	
						count++;
					}//计算一共有多少股票
					order = "select max(count),code from mystocks group by code";
					ResultSet resultSet = statement0.executeQuery(order);
					s = new String[count][2];
											
					int index=0;
					while(resultSet.next()) {
						s[index][0]=resultSet.getString(2);
						s[index][1]=resultSet.getString(1);
						index++;
					}
						
					boolean needNextPass = true;
					for(int k=1; k<s.length&&needNextPass; k++) {
						needNextPass = false;
						for(int i=0; i<s.length-k;i++) {
							int s11=Integer.parseInt(s[i][1]);
							int s21=Integer.parseInt(s[i+1][1]);
							if(s11 < s21) {
								String temp1 = s[i][0];
								s[i][0] = s[i+1][0];
								s[i+1][0] = temp1;
								
								String temp2 = s[i][1];
								s[i][1] = s[i+1][1];
								s[i+1][1] = temp2;
								needNextPass = true;
							}
						}
					}
					//排序完毕
					connection.close();					
				%>
				
				<%																
					s1 = s[0][0]+":"+s[0][1];
					s2 = s[1][0]+":"+s[1][1];
					s3 = s[2][0]+":"+s[2][1];
					s4 = s[3][0]+":"+s[3][1];
					s5 = s[4][0]+":"+s[4][1];
					s6 = s[5][0]+":"+s[5][1];
					s7 = s[6][0]+":"+s[6][1];
					s8 = s[7][0]+":"+s[7][1];
					s9 = s[8][0]+":"+s[8][1];
					s10 = "格式= 股票代码 + 三连涨次数";					
				%>
	         		<div id="stock1" style="weight:100%; height:10%">
						<p><%= s1 %></p>
					</div>
					<div id="stock2" style="weight:100%; height:10%;">
						<p><%= s2 %></p>
					</div>
					<div id="stock3" style="weight:100%; height:10%">
						<p><%= s3 %></p>
					</div>
					<div id="stock4" style="weight:100%; height:10%">
						<p><%= s4 %></p>
					</div>
					<div id="stock5" style="weight:100%; height:10%">
						<p><%= s5 %></p>
					</div>
				</div>
				<div id="message2" class="elementCenter" style="weight:50%;height:100%;float:right;">
	         		<div id="stock1" style="weight:100%; height:10%">
						<p><%= s6 %></p>
					</div>
					<div id="stock2" style="weight:100%; height:10%">
						<p><%= s7 %></p>
					</div>
					<div id="stock3" style="weight:100%; height:10%">
						<p><%= s8 %></p>
					</div>
					<div id="stock4" style="weight:100%; height:10%">
						<p><%= s9 %></p>
					</div>
					<div id="stock5" style="weight:100%; height:10%">
						<p><%= s10 %></p>
					</div>
				</div>
			</div>
		</div>
		<!-- 功能区 ------------------------------------------------------------------------------------->
		<div id="down" style="background-color:green;height:200px;width:100%;position:relative;">
			<div id="loadin" class="divCenter" 
			style="background-color:pink;height:160px;width:86%;">
				<div id="input">
					<form>
					输入股票代码查询: <input type="text" name="firstname"><br>
					</form>
				</div>
					<span id="loadin" class="elementCenter">
						<input type="button" value="查询" 
						onclick="window.open('http://chrismasin2015.club/static/wrong.html')"
						style="width:100px">
					</span>
			</div>
		<!-- 功能区 ----------------------------------------------------------------------------------->
		</div>
	</div>		
		<!-- 下方的的登录界面 -->
		
		<div id="footer" style="background-color:#00FFFF;
			height:20px;text-align:center;clear:both;">
			Copyright © chrismasin2015.club
		</div>
		<!-- 赞助 -->
</body>
</html>